exports.__esModule = true;

var _BaseSocket = require('../websocket/BaseSocket');

var _BaseSocket2 = _interopRequireDefault(_BaseSocket);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            * 通知公告模块
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            */


exports.default = class extends _BaseSocket2.default {
    // 获取通告列表
    getOaNotifyListAction() {
        var _this = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this.post();
            const oaNotifyService = _this.service('oa/OaNotifyService');
            const result = yield oaNotifyService.oaNotifyList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this.json(aj);
        })();
    }

    getNotifyListAction() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = {
                user_id: _this2.get('user_id'),
                pageSize: _this2.get('pageSize'),
                page: _this2.get('page'),
                title: _this2.get('title')
            };
            const NotifyService = _this2.service('oa/OaNotifyService');
            const res = yield NotifyService.getNotifyList(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this2.json(aj);
        })();
    }

    getNotifyListCountAction() {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = {
                user_id: _this3.get('user_id'),
                title: _this3.get('title')
            };
            const NotifyService = _this3.service('oa/OaNotifyService');
            const res = yield NotifyService.getNotifyListCount(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this3.json(aj);
        })();
    }

    getAllNotifyListAction() {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = {
                user_id: _this4.get('user_id')
            };
            const NotifyService = _this4.service('oa/OaNotifyService');
            const res = yield NotifyService.getAllNotifyList(data);
            if (!res.error) {
                aj.result = res;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this4.json(aj);
        })();
    }

    //根据user_id获取通知
    userIdOaNotifyListAction() {
        var _this5 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this5.post('params');
            const oaNotifyService = _this5.service('oa/OaNotifyService');
            const result = yield oaNotifyService.userIdOaNotifyList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this5.json(aj);
        })();
    }

    //获取通知详情
    getNotifyDetailsAction() {
        var _this6 = this;

        return _asyncToGenerator(function* () {
            const data = _this6.post('params');
            if (!data) {
                return _this6.errorJson('请传入参数');
            } else {
                try {
                    const res = yield _this6.service('oa/OaNotifyService').notifyDetails(data);
                    return _this6.successJson(res);
                } catch (error) {
                    return _this6.errorJson('查询失败');
                }
            }
        })();
    }

    //获取通知类型
    getNotifyTypeAction() {
        var _this7 = this;

        return _asyncToGenerator(function* () {

            const data = _this7.post();
            try {
                const res = yield _this7.service('oa/OaNotifyService').notifyTypes(data);
                return _this7.successJson(res);
            } catch (error) {
                return _this7.errorJson('查询失败');
            }
        })();
    }

    allUserIdOaNotifyListAction() {
        var _this8 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this8.post('params');
            const oaNotifyService = _this8.service('oa/OaNotifyService');
            const result = yield oaNotifyService.allUserIdOaNotifyList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this8.json(aj);
        })();
    }

    //分页查询接收人接收状态
    notifyIdOaNotifyListAction() {
        var _this9 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this9.post('params');
            const oaNotifyService = _this9.service('oa/OaNotifyService');
            const result = yield oaNotifyService.notifyIdOaNotifyList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this9.json(aj);
        })();
    }

    //查询全部接收状态
    allNotifyIdOaNotifyListAction() {
        var _this10 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this10.post('params');
            const oaNotifyService = _this10.service('oa/OaNotifyService');
            const result = yield oaNotifyService.allNotifyIdOaNotifyList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this10.json(aj);
        })();
    }

    //根据通知id获取通知详情
    notifyAction() {
        var _this11 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            const data = _this11.post();
            const notifyService = _this11.service('oa/OaNotifyService');
            const result = yield notifyService.notify(data);
            if (!result) {
                aj.result = result;
            } else if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this11.json(aj);
        })();
    }

    //保存文件
    saveFileAction() {
        var _this12 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let fileDate = _this12.post();
            _this12.uploadFileAction(fileDate.id);
            //   const file = this.file('file');
            //   if (file) {
            //       let file_path = await this.renameFile(file,fileDate.id);
            //       if (file_path) {
            //           fileDate.realpath = file_path.filePathStatic
            //
            //       } else {
            //           aj.success = false;
            //           aj.msg = '文件保存失败';
            //           return this.json(aj)
            //       }
            //   }
            //   // const fileService = this.service('oa/OaNotifyService');
            //   // const result = await fileService.saveFile(fileDate);
            // const result =   await this.service('sys/AttachmentService').saveFile(fileDate);
            //
            //   if (!result.error) {
            //       aj.result = result
            //
            //   } else {
            //       aj.success = false;
            //       aj.msg = '保存错误';
            //       return this.json(aj)
            //   }
            //   return this.json(aj)
        })();
    }

    // 新增通告
    addOaNotifyAction() {
        var _this13 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let addDate = _this13.post();
            const oaNotifyService = _this13.service('oa/OaNotifyService');
            const result = yield oaNotifyService.oaNotifyAdd(addDate);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '保存失败';
            }
            return _this13.json(aj);
        })();
    }

    //发送通知通告
    sendOaNotifyAction() {
        var _this14 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this14.post();
            const notifyService = _this14.service('oa/OaNotifyService');
            const result = yield notifyService.sendOaNotify(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '发送失败';
            }
            let msgBox = _this14.getSocketMsgBody();
            msgBox.title = '通知公告';
            msgBox.menuUrl = 'myOffice';
            msgBox.result.id = data.notify.id;
            // this.sendMsgByUserAction(socketBody);  //消息推送

            _this14.sendMsgByUserAction(msgBox, data.user_id, 'msg_box'); //消息推送

            return _this14.json(aj);
        })();
    }

    //发送派遣核实消息

    sendMsgNotifyAction() {
        var _this15 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this15.post();
            const msgNotifyService = _this15.service('oa/OaNotifyService');
            const result = yield msgNotifyService.sendMsgNotify(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '发送失败';
            }
            return _this15.json(aj);
        })();
    }

    //删除通知通告
    delOaNotifyAction() {
        var _this16 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this16.post();
            const delNotifyService = _this16.service('oa/OaNotifyService');

            if (data) {
                const result = yield delNotifyService.delOaNotify(data);
                if (!result.error) {
                    aj.result = result;
                    return _this16.json(aj);
                } else {
                    aj.success = false;
                    aj.msg = '删除失败';
                    return _this16.json(aj);
                }
            } else {
                aj.success = false;
                aj.msg = '请传入参数id';
                return _this16.json(aj);
            }
        })();
    }

    //修改状态
    updateOaNotifyAction() {
        var _this17 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this17.post();
            const delNotifyService = _this17.service('oa/OaNotifyService');

            if (data) {
                const result = yield delNotifyService.updateOaNotify(data);
                if (!result.error) {
                    aj.result = result;
                    return _this17.json(aj);
                } else {
                    aj.success = false;
                    aj.msg = '修改失败';
                    return _this17.json(aj);
                }
            } else {
                aj.success = false;
                aj.msg = '请传入参数id';
                return _this17.json(aj);
            }
        })();
    }

    //获取所有用户
    userListAction() {
        var _this18 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this18.get();
            const userService = _this18.service('oa/OaNotifyService');
            const result = yield userService.getUserList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this18.json(aj);
        })();
    }

    //获取微信用户
    weChatUserListAction() {
        var _this19 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this19.get();
            const userService = _this19.service('oa/OaNotifyService');
            const result = yield userService.getWeChatUserList(data);
            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this19.json(aj);
        })();
    }

    //获取所有组织机构和人员
    orgAndUserAction() {
        var _this20 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = _this20.get();
            const orgUserService = _this20.service('oa/OaNotifyService');
            const result = yield orgUserService.getOrgAndUser(data);

            if (!result.error) {
                aj.result = result;
            } else {
                aj.success = false;
                aj.msg = '查询失败';
            }
            return _this20.json(aj);
        })();
    }

    updateNotifyRecordAction() {
        var _this21 = this;

        return _asyncToGenerator(function* () {
            let aj = think.ajaxJson();
            let data = {
                id: _this21.post('id')
            };
            const delNotifyService = _this21.service('oa/OaNotifyService');

            if (data) {
                const result = yield delNotifyService.updateNotifyRecord(data);
                if (!result.error) {
                    aj.result = result;
                    return _this21.json(aj);
                } else {
                    aj.success = false;
                    aj.msg = '更新失败';
                    return _this21.json(aj);
                }
            } else {
                aj.success = false;
                aj.msg = '请传入参数id';
                return _this21.json(aj);
            }
        })();
    }
};